package org.esk.dablog.web.modules;

import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.esk.dablog.service.EntryManager;
import org.esk.dablog.ApplicationConstants;
import org.esk.dablog.model.entries.Ride;
import org.esk.dablog.modules.Module;
import org.esk.dablog.web.elements.CalendarBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.List;
import java.util.Calendar;
import java.util.Date;

/**
 * This class implements Calendar Module backend
 * User: esk
 * Date: Dec 3, 2006
 * Time: 6:09:35 PM
 * $Id:$
 */
public class CalendarModule implements Module {
    public static final String CALENDAR_BEAN_PROPERTY = "__module__calendar__bean";
    private EntryManager entryManager;


    public void initialize(String name, String prefix, HttpServletRequest request) {
        List<Integer> dates = entryManager.listMonthCalendar(Ride.class, Calendar.getInstance());
        CalendarBean calendarBean = new CalendarBean();
        calendarBean.setShowMonths(false);
        calendarBean.setCurrentDate(Calendar.getInstance());
        calendarBean.setDates(dates);
        calendarBean.setLocale(request.getLocale());
        calendarBean.setDayHref(request.getContextPath() + "/calendar.form");
        request.setAttribute(CALENDAR_BEAN_PROPERTY, calendarBean);        
    }


    public void setEntryManager(EntryManager entryManager) {
        this.entryManager = entryManager;
    }
}
